﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BattleThis.Core;
using BattleThis.Mvc;
using System.Runtime.CompilerServices;

namespace BattleThis.Controllers
{
	public class BattleController : InGameControllerAbstract
    {

		#region Variablen
		public const string AttackCommand = "Attack";
		public static readonly ReflectedControllerDescriptor Info = new ReflectedControllerDescriptor( typeof( BattleController ) );
		#endregion

		#region Properties

		#endregion

		#region Methoden

		[ActionName( AttackCommand )]
		public ActionResult Attack( int targetId )
		{
			
			if( this.GameContext.Selection.IsNone() || 
			    this.Game.CurrentPlayer.HasUnit( targetId ) )
			{
				return RedirectToAction( GameController.IndexAction ,  GameController.Info.ControllerName );
			}

			var raider = this.GameContext.Selection.Unit;
			var defender = this.Game.Map.Find( targetId ).Unit;

			this.Game.Battle.Fight( raider, defender );

			return RedirectToAction( GameController.IndexAction, GameController.Info.ControllerName );
		}

		#endregion

    }
}
